package com.tik.module_function.extension

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.ConvertUtils
import com.fenghuajueli.lib_data.entity.db.VideoInfoEntity
import com.fenghuajueli.libbasecoreui.listener.OnListClickListener
import com.fenghuajueli.libbasecoreui.utils.CustomItemDecoration
import com.fenghuajueli.libbasecoreui.widget.GridSpacingItemDecoration
import com.ijianji.module_play_video.adapter.VideoListAdapter
import com.ijianji.module_play_video.adapter.VideoRecommendGridAdapter
import com.ijianji.module_play_video.adapter.VideoSelectPositionAdapter


fun RecyclerView.initVideoListAdapter(list: MutableList<VideoInfoEntity>, onBaseItemClickListener: OnListClickListener<VideoInfoEntity>): VideoListAdapter {
    val layoutManager = LinearLayoutManager(this.context, LinearLayoutManager.VERTICAL, false)
    this.layoutManager = layoutManager
    val videoListAdapter = VideoListAdapter(this.context, list)
    this.adapter = videoListAdapter
    videoListAdapter.onBaseItemClickListener = onBaseItemClickListener
    return videoListAdapter
}


fun RecyclerView.initGridVideoListAdapter(list: MutableList<VideoInfoEntity>, onBaseItemClickListener: OnListClickListener<VideoInfoEntity>): VideoRecommendGridAdapter {
    val layoutManager = GridLayoutManager(this.context, 2)
    this.layoutManager = layoutManager
    val videoListAdapter = VideoRecommendGridAdapter(this.context, list)
    val itemDecoration = GridSpacingItemDecoration(2, ConvertUtils.dp2px(10f), true)
    this.addItemDecoration(itemDecoration)
    this.adapter = videoListAdapter
    videoListAdapter.onBaseItemClickListener = onBaseItemClickListener
    return videoListAdapter
}


fun RecyclerView.initSelectVideoPositionAdapter(list: MutableList<VideoInfoEntity>,
                                                onBaseItemClickListener: OnListClickListener<VideoInfoEntity>): VideoSelectPositionAdapter {
    val layoutManager = LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
    this.layoutManager = layoutManager
    val itemDecoration = CustomItemDecoration(this.context, ConvertUtils.dp2px(10f).toFloat(),
            ConvertUtils.dp2px(16f).toFloat())
    val videoListAdapter = VideoSelectPositionAdapter(this.context, list)
    this.adapter = videoListAdapter
    this.addItemDecoration(itemDecoration)
    videoListAdapter.onBaseItemClickListener = onBaseItemClickListener
    return videoListAdapter
}